import java.util.Scanner;

public class Answer1 {
    //牛牛冲钻五
    //
    // 模拟
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int T=in.nextInt();

        while(T-- != 0){
            int n= in.nextInt();
            int k= in.nextInt();
            char[] s=in.next().toCharArray();

            int ret=0;
            for(int i=0;i<s.length;i++ ){
                if(s[i] == 'L') ret-=1;
                else{
                    if(i-1>=0 && i-2>=0 && s[i-1] == 'W' && s[i-2] =='W') ret+=k;
                    else ret+=1;
                }
            }

            System.out.println(ret);
        }
    }
}
